package kyssion.leetcode.num101_150;

import kyssion.leetcode.util.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class code144_二叉树前序遍历 {
    public static void main(String[] args) {

    }

    List<Integer> list ;
    public List<Integer> preorderTraversal(TreeNode root) {
        list = new ArrayList<>();
        ans(root);
        return list;
    }

    public void ans(TreeNode treeNode){
        if(treeNode == null){
            return;
        }
        list.add(treeNode.val);
        ans(treeNode.left);
        ans(treeNode.right);
    }
}
